<?php
namespace app\admin\controller;

use app\admin\model\DepartmentModel;

class Department extends Base
{
	/**
	 * [部门结构树]
	 */
	public function index(){
		if(request()->isAjax()){
            $depart = new DepartmentModel();
            $departs = $depart->getDepartmentList();
            $departs = getTree(objToArray($departs), false);
            return json(msg(1, $departs, 'ok'));
        }
        return $this->fetch();
	}

	/**
	 * [添加部门]
	 */
	public function departAdd(){
        $param = input('post.');
        $depart = new DepartmentModel();
        $flag = $depart->insertDepart($param);
        return json(msg($flag['code'], $flag['data'], $flag['msg']));
    }

   	/**
	 * [编辑部门]
   	 */
    public function departEdit(){
        $param = input('post.');
        $depart = new DepartmentModel();
        $flag = $depart->editDepart($param);
        return json(msg($flag['code'], $flag['data'], $flag['msg']));
    }


    /**
	 * [删除部门]
     */
    public function departDel(){
        $id = input('param.id');
        $depart = new DepartmentModel();
        $flag = $depart->delDepart($id);
        return json(msg($flag['code'], $flag['data'], $flag['msg']));
    }
}